"""
 @作者:sipeiliu

 @邮箱:sipeiliu@163.com

 @描述:机器视觉模块
 
 @日期:2023.5.24
"""

import numpy as np
import cv2 as cv

cap = cv.VideoCapture(0)
if not cap.isOpened():
    print("Cannot open camera")
    exit()
while True:
    # 逐帧捕获
    ret, frame = cap.read()
    # 如果正确读取帧，ret为True
    if not ret:
        print("Cannot receive frame (stream end?). Exiting ...")
        break
    # 灰度帧
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    # 显示结果帧
    cv.imshow('gray frame', gray)
    if cv.waitKey(1) == ord('q'):
        break
# 释放捕获器
cap.release()
cv.destroyAllWindows()
